package com.file;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @Description: 得到文件编码集
 */
public class GetCode {

    public static void main(String[] args) throws IOException {

        BufferedInputStream bin = new BufferedInputStream(new FileInputStream("f:/test/save1.txt"));
        int p = (bin.read() << 8) + bin.read();
        String code = null;
        switch (p) {
            case 0xefbb:
                code = "UTF-8";
                break;
            case 0xfffe:
                code = "Unicode";
                break;
            case 0xfeff:
                code = "UTF-16BE";
                break;
            default:
                code = "GBK";
        }
        System.out.println("文件字符编码: " + code);
    }
}
